package com.lzdongrui.client.controller;

import com.lzdongrui.common.annotation.Log;
import com.lzdongrui.common.core.controller.BaseController;
import com.lzdongrui.common.core.domain.AjaxResult;
import com.lzdongrui.common.core.page.TableDataInfo;
import com.lzdongrui.common.enums.BusinessType;
import com.lzdongrui.common.utils.SecurityUtils;
import com.lzdongrui.system.domain.Notification;
import com.lzdongrui.system.service.ISysNoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *
 * </p>
 *
 * @author wyh
 * @since 2023/6/15 15:52
 */
@RestController
@RequestMapping("/client/notice")
public class ClientNoticeController  extends BaseController {

    @Autowired
    private ISysNoticeService noticeService;


    /**
     * 获取通知（用户端用）
     */
//    @PreAuthorize("@ss.hasPermi('system:notice:all-list-user')")
    @GetMapping("/all-list-user")
    public TableDataInfo notificationAllListUser(Notification notification)
    {
        notification.setViewerUserId(SecurityUtils.getClientUserId());
        List<Notification> list = noticeService.notificationAllList(notification);
        return getDataTable(list);
    }

    /**
     * 确认读取通知
     */
    @Log(title = "确认读取通知", businessType = BusinessType.UPDATE)
    @PutMapping("/{Ids}")
    public AjaxResult acknowledgeReceipt(@PathVariable Long Ids)
    {
        Ids = SecurityUtils.getClientUserId();
        return toAjax(noticeService.acknowledgeReceipt(Ids));
    }
}
